package com.hn658.base.message.comet.enums;

import com.hn658.base.message.common.exceptions.FilterException;


/**
 * 长连接请求异常类型
 */
public enum ExceptionType {
    ResetException(530, "服务器异常请稍后重连"),
    NoResetException(430, "客户端请求异常请修复后重新连接");

    private int code;

    private String name;

    ExceptionType(int code, String name){
        this.code = code;
        this.name = name;
    }

    /**
     * @return the code
     */
    public int getCode() {
        return code;
    }

    public String getName(){
        return name;
    }

    /**
     * 根据code值获取对应的枚举
     * @param code
     * @return
     */
    public static ExceptionType getTypeByCode(int code){
        for(ExceptionType type : ExceptionType.values()){
            if(type.getCode() == code){
                return type;
            }
        }

        throw new FilterException(FilterException.WrongDeviceType);
    }
}
